from enum import Enum

from tortoise import fields, models

from app.models.users import User


class ScheduleType(str, Enum):
    TWO_TWO = "2/2"
    FIVE_TWO = "5/2"


class ShiftType(str, Enum):
    DAY = "day"
    NIGHT = "night"


class Modality(models.Model):
    code = fields.CharField(max_length=10, unique=True, pk=True)
    name = fields.CharField(max_length=100)


class Doctor(models.Model):
    user: fields.OneToOneRelation[User] = fields.OneToOneField(
        "models.User", related_name="doctor", on_delete=fields.CASCADE
    )
    main_modality: fields.ForeignKeyRelation[Modality] = fields.ForeignKeyField(
        "models.Modality", related_name="doctors_main"
    )
    additional_modalities: fields.ManyToManyRelation[Modality] = fields.ManyToManyField(
        "models.Modality", related_name="doctors_additional"
    )
    rate_percent = fields.IntField(min_value=0, max_value=100)  # Stavka
    preferred_schedule = fields.CharEnumField(ScheduleType, null=True)
    preferred_shift = fields.CharEnumField(ShiftType, null=True)
    created_at = fields.DatetimeField(auto_now_add=True)

    class Meta:
        ordering = ["-created_at"]
